package com.hrma.controller;

import com.github.pagehelper.Page;
import com.hrma.entity.*;
import com.hrma.services.WageStatisticService;
import com.hrma.utils.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/wageStatistic")
@Slf4j
public class WageStatisticController {
    private final WageStatisticService wageStatisticService;

    public WageStatisticController(WageStatisticService wageStatisticService) {
        this.wageStatisticService = wageStatisticService;
    }

    @GetMapping("/wageCount")
    public Result<?> WageCount() {
        log.debug("收到WageCount请求!}");
        wageStatisticService.addAllEmployeeWage();
        return Result.ok(null);
    }

    @PostMapping("/list")
    public Result<ListWithCount<WageStatisticResult>> getList(@RequestBody WageStatisticDTO data) {
        log.debug("收到list请求，请求参数：{}", data);
        Page<WageStatisticResult> res = wageStatisticService.getList(data);
        if(res == null){
            return Result.ok(null);
        }
        return Result.ok(new ListWithCount<>(res.getTotal(), res));
    }

    @PatchMapping("/update")
    public Result<?> update(@RequestBody WageStatistic data) {
        log.debug("收到update请求，请求参数：{}", data);
        wageStatisticService.update(data);
        return Result.ok(null);
    }

    @DeleteMapping("/delete/{id}")
    public Result<?> delete(@PathVariable int id) {
        log.debug("收到delete请求，请求参数：{}", id);
        wageStatisticService.delete(id);
        return Result.ok(null);
    }
}
